package com.xinzhitong.www.mapper;

import com.xinzhitong.www.pojo.TrainOrgan;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * train_organ表相关操作
 *
 * @author 徐鑫,吴展鹏,黄欢欢
 */
@Repository
public interface TrainOrganMapper {

    @Select("select * from train_organ where username=#{username}")
    TrainOrgan selectTrainOrganByUsername(@Param("username") String username);

    @Select("select * from train_organ where id =#{organId}")
    Map<String,Object> selectOrganOutline(@Param("organId") Integer organId);

    @Insert("insert into train_organ(" +
            "name,\n" +
            "shortname,\n" +
            "date,\n" +
            "province,\n" +
            "city,\n" +
            "area,\n" +
            "address,\n" +
            "contact,\n" +
            "introduction,\n" +
            "username" +
            ") values(" +
            "#{name},\n" +
            "#{shortname},\n" +
            "#{date},\n" +
            "#{province},\n" +
            "#{city},\n" +
            "#{area},\n" +
            "#{address},\n" +
            "#{contact},\n" +
            "#{introduction},\n" +
            "#{username}" +
            ")")
    Integer insertTrainOrgan(TrainOrgan trainOrgan);

    @Update("update train_organ set ${field}=#{value} where ${condition} ")
    Integer updateTrainOrganOfOneField(
            @Param("field") String field,
            @Param("value") Object value,
            @Param("condition") String condition
    );

    @Select("select * from organ_user_info where username=#{username}")
    Map<String, String> selectTrainOrganInfo(@Param("username") String username);

    @Insert("insert into train_organ_has_picture value(#{trainOrganId}, #{picture})")
    Integer insertTrainOrganHasPicture(@Param("trainOrganId") Integer trainOrganId, @Param("picture") String picture);

    @Delete("delete from train_organ_has_picture where train_organ_id=#{trainOrganId}")
    void deleteTrainOrganHasPicture(@Param("trainOrganId") Integer trainOrganId);

    @Select("select name,id from train_organ")
    List<Map<String,Object>> selectTrainOrganNameAndId();

}
